<?php

function smarty_function_getsubcategory_by_topic_id($params, &$smarty) {
    //Get value from page
    $id = $params['topic_id'];
    if($id){
      //Query data

    $pntables = pnDBGetTables();
    $tpc_table  = $pntables['innoforum_topics'];
    $tpc_column = $pntables['innoforum_topics_column'];
		
    $scy_table  = $pntables['innoforum_subcategory'];		
    $scy_column = $pntables['innoforum_subcategory_column'];

      $sql = "SELECT
                $scy_table.$scy_column[id] as category_id,			
                $scy_table.$scy_column[name] as subcategory_name
              FROM 
                $tpc_table ,
                $scy_table
              WHERE
                $tpc_table.$tpc_column[id] = $id
              AND
                $scy_table.$scy_column[id] = $tpc_table.$tpc_column[subcategory_id]
							AND 
								$tpc_table.$tpc_column[subcategory_id] != 99999
							";

      $column = array("subcategory_id","subcategory_name");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);

      
			
			if(isset($objectArray)){
				$smarty->assign("subcategory_id", $objectArray['0']['subcategory_id']);
				$smarty->assign("subcategory_name", $objectArray['0']['subcategory_name']);
			}else{
				$smarty->assign("subcategory_id", NULL);
				$smarty->assign("subcategory_name", "What the hell");
			}
    }


}